package com.fr.base.background;

import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.chart.core.ChartUtils;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.Point2D.Float;

public class GradientBackground extends AbstractBackground
{
  public static int LEFT2RIGHT = 0;
  public static int TOP2BOTTOM = 1;
  private int direction = 0;
  private boolean useCell = true;
  private boolean cyclic = false;
  private float begin = 0.0F;
  private float finish = 0.0F;
  private Color color1;
  private Color color2;

  public GradientBackground()
  {
  }

  public GradientBackground(Color paramColor1, Color paramColor2, int paramInt)
  {
    this.color1 = paramColor1;
    this.color2 = paramColor2;
    this.direction = paramInt;
  }

  public void setColor1(Color paramColor)
  {
    this.color1 = paramColor;
  }

  public Color getColor1()
  {
    return this.color1;
  }

  public void setColor2(Color paramColor)
  {
    this.color2 = paramColor;
  }

  public Color getColor2()
  {
    return this.color2;
  }

  public void setDirection(int paramInt)
  {
    if ((paramInt != LEFT2RIGHT) && (paramInt != TOP2BOTTOM))
      return;
    this.direction = paramInt;
  }

  public int getDirection()
  {
    return this.direction;
  }

  public boolean isUseCell()
  {
    return this.useCell;
  }

  public void setUseCell(boolean paramBoolean)
  {
    this.useCell = paramBoolean;
  }

  public boolean isCyclic()
  {
    return this.cyclic;
  }

  public void setCyclic(boolean paramBoolean)
  {
    this.cyclic = paramBoolean;
  }

  public void setBeginPlace(float paramFloat)
  {
    this.begin = paramFloat;
  }

  public float getBeginPlace()
  {
    return this.begin;
  }

  public void setFinishPlace(float paramFloat)
  {
    this.finish = paramFloat;
  }

  public float getFinishPlace()
  {
    return this.finish;
  }

  public void paint(Graphics paramGraphics, Shape paramShape)
  {
    GradientPaint localGradientPaint = null;
    Point2D.Float localFloat1 = null;
    Point2D.Float localFloat2 = null;
    if (isUseCell())
    {
      localFloat1 = new Point2D.Float(paramShape.getBounds().x, paramShape.getBounds().y);
      if (this.direction == LEFT2RIGHT)
        localFloat2 = new Point2D.Float(paramShape.getBounds().x + paramShape.getBounds().width, paramShape.getBounds().y);
      else if (this.direction == TOP2BOTTOM)
        localFloat2 = new Point2D.Float(paramShape.getBounds().x, paramShape.getBounds().y + paramShape.getBounds().height);
    }
    else if (this.direction == LEFT2RIGHT)
    {
      localFloat1 = new Point2D.Float(this.begin, paramShape.getBounds().y);
      localFloat2 = new Point2D.Float(this.finish, paramShape.getBounds().y);
    }
    else if (this.direction == TOP2BOTTOM)
    {
      localFloat1 = new Point2D.Float(paramShape.getBounds().x, this.begin);
      localFloat2 = new Point2D.Float(paramShape.getBounds().x, this.finish);
    }
    if ((this.color1 == null) || (this.color2 == null))
      return;
    localGradientPaint = new GradientPaint(localFloat1, this.color1, localFloat2, this.color2, this.cyclic);
    if (localGradientPaint == null)
      return;
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    Paint localPaint = localGraphics2D.getPaint();
    localGraphics2D.setPaint(localGradientPaint);
    localGraphics2D.fill(paramShape);
    localGraphics2D.setPaint(localPaint);
  }

  public void toImage()
  {
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof GradientBackground))
      return false;
    GradientBackground localGradientBackground = (GradientBackground)paramObject;
    return ((getBeginPlace() == localGradientBackground.getBeginPlace()) && (getFinishPlace() == localGradientBackground.getFinishPlace()) && (isCyclic() == localGradientBackground.isCyclic()) && (isUseCell() == localGradientBackground.isUseCell()) && (this.direction == localGradientBackground.getDirection()) && (comparaColor(getColor1(), localGradientBackground.getColor1())) && (comparaColor(getColor2(), localGradientBackground.getColor2())));
  }

  public boolean comparaColor(Color paramColor1, Color paramColor2)
  {
    if ((paramColor1 == null) || (paramColor2 == null))
      return ((paramColor1 == null) && (paramColor2 == null));
    return (paramColor1.getRGB() == paramColor2.getRGB());
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = new JSONObject();
    localJSONObject.put("direction", this.direction);
    localJSONObject.put("beginColor", ChartUtils.color2JS(this.color1));
    localJSONObject.put("endColor", ChartUtils.color2JS(this.color2));
    localJSONObject.put("begin", this.begin);
    localJSONObject.put("finish", this.finish);
    localJSONObject.put("cyclic", this.cyclic);
    localJSONObject.put("useCell", this.useCell);
    return localJSONObject;
  }

  public String getBackgroundType()
  {
    return "GradientBackground";
  }
}